<template>
    <div>
        <!-- 表格 -->
        <!-- <el-table :data="getMenuList" style="width: 100%;margin-bottom: 20px;" border> -->
        <el-table :data="getMenuList" style="width: 100%;margin-bottom: 1.25rem;" row-key="id" border default-expand-all
            :tree-props="{ children: 'children' }" class="table">
            <el-table-column prop="id" label="菜单编号" width="180" hasChildren>
            </el-table-column>
            <el-table-column prop="title" label="菜单名称">
            </el-table-column>
            <el-table-column prop="pid" label="上级菜单">
            </el-table-column>
            <el-table-column prop="icon" label="菜单图标">
                <template slot-scope="item">
                    <div>
                        <i :class="item.row.icon"></i>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="url" label="菜单地址">
            </el-table-column>
            <el-table-column prop="status" label="状态">
                <!-- 作用域插槽 -->
                <template slot-scope="item">
                    <div>
                        <!-- item.row  表格的每一行 -->
                        {{ item.row.status == 1 ? '启用' : '禁用' }}
                    </div>
                </template>

            </el-table-column>
            <el-table-column prop="amount3" label="操作">
                <!-- 开启槽口 -->
                <template slot-scope="item">
                    <div>
                        <el-button type="success" size="small" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" size="small" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>

            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { menuDelete, menuInfo } from '../../request/api';
// 引入vuex的辅助函数
import { mapGetters, mapActions } from 'vuex';
export default {
    data() {
        return {
        }
    },

    methods: {
        // 从仓库中获取菜单列表
        ...mapActions({
            getMenu: 'menu/getMenuList'
        }),
        // 删除单挑数据
        del(id) {
            // 询问用户是否要删除
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //调取删除接口
                menuDelete({ id }).then(res => {
                    console.log(res);
                    // 删除成功
                    if (res.code == 200) {
                        // 重新渲染数据
                        this.getMenu();
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        // 编辑数据
        edit(id) {
            // 弹出弹窗
            this.$emit('isShow', id);

        }
    },
    mounted() {
        this.getMenu();

    },
    watch: {},
    computed: {
        ...mapGetters({
            getMenuList: 'menu/getMenuList'
        })
    },
    filters: {},
    components: {},
}
</script>
<style scoped>
.el-table {
    text-align: center;
}
</style>